package com.essearch.common;

import com.essearch.entity.Item_main;
import com.essearch.entity.Item_person_base;
import com.essearch.entity.Jhrw_item;
import com.essearch.entity.Jhrw_unit;

/**
 * 各表使用到的字段
 * @author ASUS
 */
public enum TableFieldEnum {

    //
    MAIN("item_main", Item_main.class, "itemId", "itemName", "qwcx", "", ""),
    JHRW_ITEM("jhrw_item", Jhrw_item.class, "jhrwId", "jhrwName", "qwcx", "", ""),
    JHRW_UNIT("jhrw_unit", Jhrw_unit.class, "unitId", "unitName", "unitName", "itemId", "flag"),
    PERSON("item_person_base", Item_person_base.class, "personId", "name", "name", "itemId", "flag"),
    ;

    /**
     * unique id
     */
    private String uid;
    /**
     * 类型
     */
    private String type;
    /**
     * 类
     */
    private Class<?> clazz;
    /**
     * 标题字段
     */
    private String title;
    /**
     * 内容字段
     */
    private String content;
    /**
     * 目标获取字段
     */
    private String targetField;
    /**
     * 过滤字段
     */
    private String filterField;

    TableFieldEnum(String type, Class<?> clazz, String uid, String title, String content, String targetField, String filterField){
        this.type=type;
        this.clazz=clazz;
        this.uid=uid;
        this.title=title;
        this.content=content;
        this.targetField=targetField;
        this.filterField=filterField;
    }
    public String type() {
        return this.type;
    }
    public Class<?> clazz() {
        return this.clazz;
    }
    public String uid() {
        return this.uid;
    }
    public String title() {
        return this.title;
    }
    public String content() {
        return this.content;
    }
    public String targetField() {
        return this.targetField;
    }
    public String filterField() {
        return this.filterField;
    }

    public static String getValue(String type) {
        for (TableFieldEnum tableFieldEnum : TableFieldEnum.values()) {
            if (tableFieldEnum.type.equals(type)) {
                return tableFieldEnum.uid();
            }
            if (tableFieldEnum.targetField.equals(type)) {
                return tableFieldEnum.targetField();
            }
        }
        return "id";
    }

    public static Class<?> getClazz(String type){
        for (TableFieldEnum tableFieldEnum : TableFieldEnum.values()) {
            if (tableFieldEnum.type.equals(type)) {
                return tableFieldEnum.clazz();
            }
        }
        return null;
    }
}
